/*jslint vars:true plusplus:true devel:true*/

//=========================================================
// Interactive Digital Media Diploma
// CUFDIG404A_R1: Introduction to Scripting
// Assignment 3
// Author: Ben
// File: buggy.js
// Description: Buggy functionality
//=========================================================

function BuggyMissile(sprite) {
    "use strict";
    var self = this;
    var startHeight = 200;

    var entity = new Entity(sprite, 100, startHeight);

    // the bullet has been hit
    this.onHit = function () {
        // on hit functionality here
        
    };

    this.setEnabled = function(enabled){
        entity.isVisible = enabled;
        collider.isEnabled = enabled;
    };

    this.isEnabled = function(){
        return entity.isVisible;
    };

    var collider = new Collider(entity, 10,window.game.buggyLayer, 0, 0, self.onHit);

    var y_velocity = -300;

    var y_accelleration = -50;


    var x_velocity = 0;

    // update the Bullet every frame
    this.update = function () {

        y_velocity += y_accelleration/window.game.frameRate;

   // update y
        entity.y += y_velocity / window.game.frameRate;

        entity.x += x_velocity / window.game.frameRate;

        if (entity.y < -10){
            self.setEnabled(false);
        }
    };

    //
    this.start = function ( x,y) {
        entity.x = x;
        entity.y = y;
    };
}
